package
{
	import as3isolib.display.IsoSprite;
	
	import flash.display.Sprite;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import flashx.textLayout.formats.Float;

	public class PopupText extends IsoSprite
	{
		private var startTime: Number;
		private var endTime: Number;
		
		private var textSprite:Sprite = new Sprite();
		private var text: TextField;
		private var alpha: Number = 1;
		public var complete: Boolean = false;
		public var e:Engine;
		private var filter : GlowFilter;
		
		/**
		 * Class to hold the information for a building progress bar, showing the level of completion of a building in progress.
		 * 
		 * @param b: The building object of which this progress bar is representing.
		 * @param msg: The message to display.
		 * @param color: The color of the outline of the text. Valid values are in the hexadecimal format 0xRRGGBB.
		 */
		public function PopupText(engine:Engine, msg:String, color:uint, xPos:int, yPos:int){
			
			this.x = (xPos+0.7)*Render.gridWidth;
			this.y = (yPos+0.5)*Render.gridWidth;
			e = engine;
			
			filter = Formatting.getOutlineFilter(1.2)[0] as GlowFilter;
			text = Formatting.newSubtitle(msg, color);
			textSprite.addChild(text);
			
			e.progressLayer.addChild(this);
			e.popupTexts.push(this);
		}
		
		public function updateGraphics():void{
			alpha -= 1/(15*2);
			
			filter.alpha = alpha;
			text.filters = new Array(filter);
			text.alpha = alpha;
			
			if (alpha < 0){
				complete = true;
				/* make text disappear */
				text.visible = false;
				sprites = [];
				e.progressLayer.removeChild(this);
				return;
			}
			
			sprites = [textSprite];
		}
	}
}